package com.jie.langlangmall.portal.controller;

import com.jie.langlangmall.common.api.CommonResult;
import com.jie.langlangmall.model.UmsMemberReceiveAddress;
import com.jie.langlangmall.portal.service.UmsMemberReceiveAddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Jie
 * @Date 2024/11/26
 * @Email 3217998214@qq.com
 * @Description 用户收货地址管理
 */
@RestController
@Tag(name = "UmsMemberReceiveAddressController", description = "会员收货地址管理")
@RequestMapping("/member/address")
public class UmsMemberReceiveAddressController {

    @Autowired
    private UmsMemberReceiveAddressService memberReceiveAddressService;

    @Operation(summary = "添加收货地址")
    @PostMapping("/add")
    public CommonResult<?> add(@RequestBody UmsMemberReceiveAddress address) {
        memberReceiveAddressService.add(address);
        return CommonResult.success();
    }

    @Operation(summary = "删除收货地址")
    @PostMapping("/delete/{id}")
    public CommonResult<?> delete(@PathVariable Long id) {
        memberReceiveAddressService.delete(id);
        return CommonResult.success();
    }

    @Operation(summary = "修改收货地址")
    @PostMapping("/update/{id}")
    public CommonResult<?> update(@PathVariable Long id, @RequestBody UmsMemberReceiveAddress address) {
        memberReceiveAddressService.update(id, address);
        return CommonResult.success();
    }

    @Operation(summary = "获取所有收货地址")
    @GetMapping("/list")
    public CommonResult<List<UmsMemberReceiveAddress>> list() {
        List<UmsMemberReceiveAddress> addressList = memberReceiveAddressService.list();
        return CommonResult.success(addressList);
    }

    @Operation(summary = "获取收货地址详情")
    @GetMapping("/{id}")
    public CommonResult<UmsMemberReceiveAddress> getItem(@PathVariable Long id) {
        UmsMemberReceiveAddress address = memberReceiveAddressService.getItem(id);
        return CommonResult.success(address);
    }

}
